package com.example.freemarker.template;

import com.alibaba.fastjson.JSONObject;
import com.example.annotations.Autowired;
import com.example.annotations.Compontent;
import com.example.db.model.IPage;
import com.example.freemarker.config.DirectiveHandler;
import com.example.freemarker.config.FreemarkerCompontent;
import com.example.freemarker.config.TemplateDirective;
import com.example.model.title.model.TitleModel;
import com.example.model.title.model.TitleModelExt;
import com.example.model.title.service.TitleModelService;

/**
 * @Classname TitleModelTemplate
 * @Description TODO
 * @Date 2022/8/7 21:55
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@FreemarkerCompontent("titlemodel")
@Compontent
public class TitleModelTemplate extends TemplateDirective {

    @Autowired
    TitleModelService titleModelService;

    @Override
    public String getName() {
        return "titlemodel";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        Integer pageNum=handler.getInteger("pageNum");
        Integer pageSize=handler.getInteger("pageSize");
        String keyword=handler.getString("keyword");
        JSONObject obj=new JSONObject();
        obj.put("keyword",keyword);
        IPage<TitleModelExt> titleModelIPage=titleModelService.page(pageNum,pageSize,obj);
        handler.put(RESULT,titleModelIPage).render();
    }
}
